﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ASCalpuff.FileLayers
{
    public class MG8 : Group
    {
        private List<US> m_US = new List<US>();

        public List<US> US
        {
            get { return m_US; }
            /// set { m_US = value; }
        }


        public  string WriteToGroup()
        {
            string ResultStr = "", TempStr;
            string END = "\r\n";

            TempStr = "INPUT GROUP: 8 -- Upper air meteorological station parameters" + END;
            ResultStr += TempStr;

            TempStr = "UPPER AIR STATION VARIABLES" + END;
            ResultStr += TempStr;

            TempStr = "         Name    ID      X coord.   Y coord.  Time zone" + END;
            ResultStr += TempStr;

            int i = 1;
            foreach (US myus in this.US)
            {
                string A = new string(myus.CUNAM);
                TempStr = "! US" + i.ToString() + "  ='" + A + "'    " + myus.IDUSTA.ToString() + "       " + Math.Round(myus.XUSTA, 3).ToString()
                       + "     " + Math.Round(myus.YUSTA, 3).ToString() + "   " + myus.XUTZ.ToString() + "    " + "  !" + END;

                ResultStr += TempStr;

                i++;

            }

            TempStr = "! END !" + END;
            ResultStr += TempStr;

            TempStr = StrWriter.GetCLine();
            ResultStr += TempStr;

            return ResultStr;


        }

        public override void ReadFromGroup(Dictionary<string, string> dic)
        {
            //int p = -1;
            US u = new US();

            foreach (KeyValuePair<string, string> m_dic in dic)
            {
                //p += 1;
                //if (m_dic.Key == "SS" +p)
                //{

                //}
                this.US.Add(u.ReadFromGroup(m_dic.Value));
            }
        }

    }



    public class US : ICloneable
    {
        //4字符站名，必须包含在单引号中，如'STA1','STA2'
        //前引号必须位于每个记录的第9（或大于9列）
        char[] m_CUNAM = new char[4];

        public char[] CUNAM
        {
            get { return m_CUNAM; }
            set { m_CUNAM = value; }
        }

        //站点编码，   五     位有效数字
        int m_IDUSTA;

        public int IDUSTA
        {
            get { return m_IDUSTA; }
            set { m_IDUSTA = value; }
        }

        //地面站点的X,Y坐标
        double m_XUSTA;

        public double XUSTA
        {
            get { return m_XUSTA; }
            set { m_XUSTA = value; }
        }
        double m_YUSTA;

        public double YUSTA
        {
            get { return m_YUSTA; }
            set { m_YUSTA = value; }
        }

        //站点所在时区（05东部标准时间，06中部标准时间，07山地标准时间，08太平洋标准时间）
        double m_XUTZ;

        public double XUTZ
        {
            get { return m_XUTZ; }
            set { m_XUTZ = value; }
        }


        public US ReadFromGroup(string str)
        {
            US u = new US();

            this.CUNAM = StrWriter.GetString(str, 1).ToCharArray();
            this.IDUSTA = Convert.ToInt32(StrWriter.GetString(str, 2));
            this.XUSTA = Convert.ToDouble(StrWriter.GetString(str, 3));
            this.YUSTA = Convert.ToDouble(StrWriter.GetString(str, 4));
            this.XUTZ = Convert.ToDouble(StrWriter.GetString(str, 5));

            return u;
        }
        public object Clone()
        {
            US obj = new US();
            obj = (US)this.MemberwiseClone();
            string A = new string(this.CUNAM);
            obj.CUNAM = StrWriter.GetString(A, 1).ToCharArray();
            return obj;
        }

    }





}
